package com.ruoyi.web.service.impl;

import java.util.Date;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.web.mapper.UserOrderMapper;
import com.ruoyi.web.domain.UserOrder;
import com.ruoyi.web.service.IUserOrderService;

/**
 * 销售单Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-06-11
 */
@Service
public class UserOrderServiceImpl implements IUserOrderService 
{
    @Autowired
    private UserOrderMapper userOrderMapper;

    /**
     * 查询销售单
     * 
     * @param id 销售单主键
     * @return 销售单
     */
    @Override
    public UserOrder selectUserOrderById(Long id)
    {
        return userOrderMapper.selectUserOrderById(id);
    }

    /**
     * 查询销售单列表
     * 
     * @param userOrder 销售单
     * @return 销售单
     */
    @Override
    public List<UserOrder> selectUserOrderList(UserOrder userOrder)
    {
        return userOrderMapper.selectUserOrderList(userOrder);
    }

    /**
     * 新增销售单
     * 
     * @param userOrder 销售单
     * @return 结果
     */
    @Override
    public int insertUserOrder(UserOrder userOrder)
    {
        userOrder.setCreateTime(DateUtils.getNowDate());
        return userOrderMapper.insertUserOrder(userOrder);
    }

    /**
     * 新增销售单
     * 
     * @param userOrder 销售单
     * @return 结果
     */
    @Override
    public UserOrder insertUserOrderReturnUserOrder(UserOrder userOrder)
    {
        userOrder.setCreateTime(DateUtils.getNowDate());
        userOrderMapper.insertUserOrder(userOrder);
        return userOrder;
    }
    

    /**
     * 修改销售单
     * 
     * @param userOrder 销售单
     * @return 结果
     */
    @Override
    public int updateUserOrder(UserOrder userOrder)
    {
        userOrder.setUpdateTime(DateUtils.getNowDate());
        return userOrderMapper.updateUserOrder(userOrder);
    }

        /**
     * 修改销售单
     * 
     * @param userOrder 销售单
     * @return 结果
     */
    @Override
    public UserOrder updateUserOrderReturnUserOrder(UserOrder userOrder)
    {
        userOrder.setUpdateTime(DateUtils.getNowDate());
        userOrderMapper.updateUserOrder(userOrder);
        return userOrder;
    }

    /**
     * 批量删除销售单
     * 
     * @param ids 需要删除的销售单主键
     * @return 结果
     */
    @Override
    public int deleteUserOrderByIds(Long[] ids)
    {
        return userOrderMapper.deleteUserOrderByIds(ids);
    }

    /**
     * 删除销售单信息
     * 
     * @param id 销售单主键
     * @return 结果
     */
    @Override
    public int deleteUserOrderById(Long id)
    {
        return userOrderMapper.deleteUserOrderById(id);
    }

    /**
     * 根据订单id更新订单状态
     * 
     * @param ids 订单id集合
     * @param isSettlement 订单状态
     * @return 结果
     */
    @Override
    public int updateUserOrderIsSettlementByOrderIds(Long[] ids, String isSettlement)
    {
        return userOrderMapper.updateUserOrderIsSettlementByOrderIds(ids, isSettlement);
    }

    @Override
    public List<UserOrder> selectListByCompanyIdAndMerchantId(Long companyId, Long merchantId) 
    {
        return userOrderMapper.selectListByCompanyIdAndMerchantId(companyId,merchantId);
    }

    @Override
    public int updateUserOrderIsSettlementByDate(Date start, Date end, String isSettlement) {

        return userOrderMapper.updateByDate(start,end,isSettlement);
    }

    @Override
    public List<UserOrder> selectUserOrdeByIds(Long[] ids) {
        return userOrderMapper.selectUserOrderByIds(ids);
    }
}
